- name: install copr repo
  copy: src="copr.repo" dest="/etc/yum.repos.d/copr.repo"

- name: install pkgs
  yum: state=present pkg={{ item }}
  with_items:
    - dnf
    - dnf-plugins-core
    - mock
#    - mock-lvm
    - createrepo_c
    - yum-utils
    - pyliblzma
    - rsync
    - openssh-clients
    - rsync
    - libselinux-python
    - libsemanage-python
    - yum
    - scl-utils-build
    - ethtool
#    - fedpkg-copr
# BZ 1241507
- shell: yum-deprecated install -y fedpkg-copr || yum install -y fedpkg-copr

# This needs to be updated for python-fedora
- shell: yum-deprecated update -y python-requests || yum install -y python-requests

- get_url: url=https://kojipkgs.fedoraproject.org//packages/mock/1.2.12/1.fc21/noarch/mock-1.2.12-1.fc21.noarch.rpm dest=/tmp/
- yum: state=present name=/tmp/mock-1.2.12-1.fc21.noarch.rpm

- name: make sure newest rpm
  # todo: replace with dnf after ansible 1.9 is available
  yum: name={{ item }} state=latest
  with_items:
    - rpm
    - glib2
    - ca-certificates

- copy: src=files/fedpkg-copr.conf dest=/etc/rpkg/fedpkg-copr.conf

- name: put updated mock configs into /etc/mock
  template: src=files/mock/{{ item }} dest=/etc/mock
  with_items:
    - site-defaults.cfg

# TODO: file globs or ansible escaping works strange, now using predefined file location
#- name: "fix mock configs to use nearest mirror"
#  # Affects only some fedora configs ... repo urls are tricky. TODO: add for epel
#  shell: "ls -1 /etc/mock/fedora*.cfg"
#  register: mock_fedora_configs_to_patch

- name: "patch mock.cfg"
  replace: >
        dest={{ item }}
        regexp='^metalink=https://mirrors.fedoraproject.org/metalink\?repo=updates-released-f\$releasever&arch=\$basearch'
        replace='baseurl=http://infrastructure.fedoraproject.org/pub/fedora/linux/updates/$releasever/$basearch/'
  with_items: #mock_fedora_configs_to_patch.stdout_lines
  -  /etc/mock/fedora-21-i386.cfg
  -  /etc/mock/fedora-21-x86_64.cfg
  -  /etc/mock/fedora-22-i386.cfg
  -  /etc/mock/fedora-22-x86_64.cfg
  -  /etc/mock/fedora-23-i386.cfg
  -  /etc/mock/fedora-23-x86_64.cfg


# ansible doesn't support simultaneously usage of async and with_* options
# it's not even planned for implementation, see https://github.com/ansible/ansible/issues/5841
- name: prepare cache
  when: prepare_base_image is defined
  async: 14400
  shell: "for i in epel-5-i386 epel-5-x86_64 epel-6-i386 epel-6-x86_64 epel-7-x86_64 fedora-20-i386 fedora-20-x86_64 fedora-21-i386 fedora-21-x86_64 fedora-22-i386 fedora-22-x86_64 fedora-23-i386 fedora-23-x86_64 fedora-rawhide-i386 fedora-rawhide-x86_64; do mock --init -r $i; done"

- name: mockbuilder user
  user: name=mockbuilder groups=mock

- name: mockbuilder .ssh
  file: state=directory path=/home/mockbuilder/.ssh mode=0700 owner=mockbuilder group=mockbuilder

- name: mockbuilder authorized_keys
  authorized_key: user=mockbuilder key='{{ lookup('file', '/home/copr/provision/files/buildsys.pub') }}'

- name: root authorized_keys
  authorized_key: user=root key='{{ lookup('file', '/home/copr/provision/files/buildsys.pub') }}'

- lineinfile: dest=/etc/security/limits.conf line="* soft nofile 10240" insertafter=EOF
- lineinfile: dest=/etc/security/limits.conf line="* hard nofile 10240" insertafter=EOF

- name: disable core dumps
  ini_file: dest=/etc/systemd/coredump.conf section=Coredump option=Storage value=none
#  notify:
#  - systemctl daemon-reload
